const app= getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    List :[
        {
            "LeftId": 1,
            "LeftName": "全部车型",
            "LeftNotice": "21款可租",
            "RightList": [
            {
                "RightId": 11,
                "RightName": "商品11"
            },
            ]
        },
        {
            "LeftId": 2,
            "LeftName": "小卡",
            "LeftNotice": "11款可租",
            "RightList": [
            {
                "RightId": 21,
                "RightName": "商品21"
            },
            ]
        },
        {
            "LeftId": 3,
            "LeftName": "小面",
            "LeftNotice": "11款可租",
            "RightList": [
            {
                "RightId": 21,
                "RightName": "商品21"
            },
            ]
        },
        {
            "LeftId": 4,
            "LeftName": "轻卡",
            "LeftNotice": "11款可租",
            "RightList": [
            {
                "RightId": 21,
                "RightName": "商品21"
            },
            ]
        },
        {
            "LeftId": 5,
            "LeftName": "中卡",
            "LeftNotice": "11款可租",
            "RightList": [
            {
                "RightId": 21,
                "RightName": "商品21"
            },
            ]
        },
        {
            "LeftId": 6,
            "LeftName": "新能源",
            "LeftNotice": "11款可租",
            "RightList": [
            {
                "RightId": 21,
                "RightName": "商品21"
            },
            ]
        },
    ],
    selectLeftId : null,
		selectRightId : null,
		currentIndex_L : null,
		currentIndex_R : null,
        scrollTop : 0,
        showMore:0,
        selectAll:0,
        allArray:[{id:0,name:'综合排序'},{id:1,name:'低价优先'},{id:2,name:'高价优先'},],

        showSelect:0,
        brand:0,
        peice:0,
        more:0,
        other:0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let that  = this;
    var deviceInfo = wx.getDeviceInfo();  
    console.log(options); 
    let d = app.globalData;

    that.setData({
        width:d.windowWidth,
        height:d.windowHeight,
        statusBarHeight:d.statusBarHeight,
        navHeight:d.navHeight,
        marginTop:d.navTitleTop,
        bottom:d.bottom,
        domain:d.domain,
       imgUrl:d.imgUrl,
        platform:deviceInfo.platform
      })
      this.setData({
        city_id:options.city_id,
        rentType:options.rentType,
        year:options.year,
        month:options.month,
        day:options.day,
        nextYear:options.nextYear
      })
  },
  goBack:function(){
    wx.navigateBack();
  },
  goIndex:function(){
    wx.reLaunch({
      url: '../index/index',
    })
  },
  getTruckList(city_id,rent_type,brand,price,order,other){
     let that = this;
       wx.request({
        url: app.globalData.domain+'/wechat/rent/getTruckList',
        data:{from:'shop',city_id:city_id,rent_type:rent_type,brand:brand,order:order,price:price,other:other},
        success:res=>{
            console.log(res)
            var data=res.data;
            var model=[];
            var models=data.models;
            console.log(data);
    
            that.setData({
           // city:data.list,
  
        
            })
        }
    })

  },
  startDate(){
    let d = this.data;
    wx.navigateTo({
      url: 'calendar?rentType='+d.rentType,
    })
  },
  getDefault(){
    let that = this;
    var city = wx.getStorageSync('city');
    if(city== undefined || city  == ''){
      wx.request({
        url: app.globalData.domain+'/wechat/home/getCity',
        data:{from:1},
        success:res=>{
            console.log(res)
            var data=res.data;
            var model=[];
            var models=data.models;
            console.log(data);
    
            that.setData({
            city:data.list,
            company_img:data.company_img
        
            })
        }
    })
    } else {
      this.setData({
        city:city
      })
    }
    var rent_type = wx.getStorageSync('rent_type');
    if(rent_type == undefined || rent_type  == ''){
      wx.request({
        url: app.globalData.domain+'/wechat/home/getRentType',
        data:{from:1},
        success:res=>{
            console.log(res)
            var d=res.data;
        
            console.log(d);
            wx.getStorageSync('rent_type',d.rent_type)
            that.setData({
            rent_type:d.rent_type,
      
        
            })
        }
    })
    }else{
      this.setData({
        rent_type:rent_type
      })
    }
 

  },
gotoEdit(e){
  this.setData({
    showSelect:1,
    showMore:0
  })
},
closeEdit(e){
  this.setData({
    showSelect:0,
    showMore:0
  })
},
setMore(e){
    var showMore = this.data.showMore;
    if(showMore == 0){
        console.log(e);
        var moreTop = e.detail.y;
        console.log(moreTop);
        this.setData({
            showMore:1,
            moreTop:moreTop
        })
    }else{
        this.setData({
            showMore:0
        })  
    }
    
},
setAll(e){
    var v = e.currentTarget.dataset;
    var selectAll = this.data.selectAll;
    if(selectAll!=v.all){
        this.setData({
            selectAll:v.all,
            showMore:0
        })
    }
},
  bindleLeftItemTap(e) {
    const {index} = e.currentTarget.dataset;
    this.setData({
        currentIndex_L:index,
        currentIndex_R : null,
        selectLeftId : this.data.List[index].LeftId,
        selectRightId : null,
        scrollTop : 0,
    }) 
},
showStore(){
  var maskTitle ='切换城市';
  var maskHeight=0;
  maskHeight = 160;
 

  this.setData({
      showStore:1,
      maskTitle:maskTitle,
      maskHeight:maskHeight
  })
},
closeStore(){
  this.setData({
      showStore:0
  })
},
showRentType(){
  var maskTitle ='租车类型';
  var maskHeight=0;
  maskHeight = 160;
  let that = this;

  this.setData({
      showRentType:1,
      maskTitle:maskTitle,
      maskHeight:maskHeight
  })
},
closeRentType(){
  this.setData({
      showRentType:0
  })
},
setCity(e){
console.log(e);
  var city_id = e.currentTarget.dataset.city_id;
  this.setData({
      city_id:city_id,
      showStore:0
  })
},
setRentType(e){
  console.log(e);
  var rentType = e.currentTarget.dataset.renttype;
  var rentDate;
 
  var nextYear;
 let d = this.data;
 var year = d.year ;
 var rent_type = d.rent_type;
rent_type.forEach(function(key,value){
  console.log(key)
  if(rentType==key.id){
    nextYear = d.year + key.year;
  }
});
  
  this.setData({
      rentType:rentType,
 
      nextYear:nextYear,
      showRentType:0
  })
},
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    let d = this.data;
    this.getDefault();
    this.getTruckList(d.city_id,d.rentType,d.brand,d.price,d.order,d.other)
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})